package fictional.GUI;

import java.io.IOException;
import java.util.Date;

import org.jdesktop.application.Application;

import fictional.Common.IBL;
import fictional.Common.PokeItem;
import fictional.Common.Response;
import fictional.Common.ShortCharacterItem;

/**
 * This task performs the poke another character action.
 */
public class PokeTask extends DefaultTask{

	ShortCharacterItem characterToPoke;
	ShortCharacterItem characterPoking;
	
	public PokeTask(Application application) {
		super(application);
	}

	public void setTask(IBL BL, GUI gui, ShortCharacterItem characterToPoke, ShortCharacterItem characterPoking)
	{
		this.BL = BL;
		this.gui = gui;
		this.characterToPoke = characterToPoke;
		this.characterPoking = characterPoking;
	}
	
    @Override
    protected Object doInBackground() throws IOException, InterruptedException
    {
        response = new Response();
        PokeItem poke = new PokeItem(0, characterPoking, characterToPoke, new Date());
        BL.insertPoke(poke, response);
        
        if (response.isIs_Success())
        {
        	isSuccessMessageNeeded = true;
        	successMessage = "Poked successfully!";
        }
        else
        {
        	errorTitle = "Error Poking Character";
        }
        return null;
    }
}
